﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAF.Entity;
using Card.Common;

namespace Card.Web
{
    public partial class ChangeCity : BasePage
    {
        public string Target
        {
            get
            {
                return Request.QueryString["Target"] == null ? string.Empty : Request.QueryString["Target"];
            }
        }

        protected override void InitArea()
        {
            _Area = Card.Common.AreaCache.GetAreaByCode(CardWebUtility.GetAreaCode());
            if ((_Area == null 
                || string.Compare(_Area.IsActive, CONST.YES_NO.YES) != 0)
                && this.ValidateCity
                && this.SiteDomain.ToLower().IndexOf(Request.Url.Host.ToLower()) < 0)
            {
                _Area = Card.Common.AreaCache.GetAreaByCode(Card.Security.CookieManager.GetArea());
                if (_Area == null || string.Compare(_Area.IsActive, CONST.YES_NO.YES) != 0)
                {
                    Response.Redirect(string.Format("{0}/changecity.aspx?Target={0}", SiteDomain, this.Target));
                }
                else
                {
                    Response.Redirect(string.Format("{0}{1}", _Area.SiteCode.TrimEnd('/'), this.Request.Url.AbsolutePath));
                }
            }
            else if ((_Area == null || string.Compare(_Area.IsActive, CONST.YES_NO.YES) != 0) && !this.ValidateCity)
            {
                _Area = Card.Common.AreaCache.GetAreaByCode(Card.Security.CookieManager.GetArea());
                if (_Area == null || string.Compare(_Area.IsActive, CONST.YES_NO.YES) != 0)
                {
                    _Area = Card.Common.AreaCache.GetAreaByCode(CONST.MainArea);
                }
            }            
        }

        protected override void OnInit(EventArgs e)
        {

            base.OnInit(e);
        }       

        protected void Page_Load(object sender, EventArgs e)
        {
            this.DoInit();
        }

        private void DoInit()
        {
            
        }
       
    }
}
